package com.example.maxboxtwo.utils.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.maxboxtwo.R;
import com.example.maxboxtwo.components.function.LED.LEDFunction;
import com.example.maxboxtwo.utils.listeners.LEDListener;

public class LEDViewAdapter extends RecyclerView.Adapter<LEDViewAdapter.ViewHolder> {
    private int [] images;
    private LEDFunction ledFunction;
    public LEDViewAdapter(int []images, LEDFunction ledFunction) {
        this.ledFunction = ledFunction;
        this.images = images;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // when creating the view, we need to load layout of file
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.led_recycle_item,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;


    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Integer number = images[position];
        holder.imageView.setImageResource(number);
        holder.imageView.setTag(number);
        holder.imageView.setOnClickListener(new LEDListener(ledFunction));

    }

    @Override
    public int getItemCount() {
        return images.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        //in the view ,we can initialize some components that we want
        private ImageView imageView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.ledItemImage);
        }
    }
}
